package cn.honqun.tinycms.common.json;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;

/**
 * 长整型序列化，长整型序列化为字符串，可以防止Javascript丢失精度
 */
public class LongSerializer extends JsonSerializer<Long> {
    @Override
    public void serialize(Long id, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
        if (id != null) {
            jsonGenerator.writeString(id.toString());
        }
    }
}
